package Text1;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:墨琦
 * Data:2023-04-09
 * Time:11:45
 */
public class Text {
    public  static MyList.List Connect(MyList.List one, MyList.List two)
    {
        MyList.List kk=new MyList.List(-1);
        MyList.List cur=kk;
        kk.next=null;
        while(two!=null&&one!=null)
        {
            if(two.data>one.data)
            {
                cur.next=one;
                cur=cur.next;
                one=one.next;
            }
            else{
                cur.next=two;
                cur=cur.next;
                two=two.next;
            }
        }
        if(two!=null)
        {
            cur.next=two;
        }
        if(one!=null)
        {
            cur.next=one;
        }
        return kk.next;
    }
     //链表的回文串
    public static void main(String[] args) {
        MyList one=new MyList();
        for(int i=10;i<14;i++)
        {
            one.insertTail(i+1);
        }
        for(int i=15;i>11;i--)
        {
            one.insertTail(i-1);
        }
        one.show();
        System.out.println(one.Palindrome(one.head));
    }
    //取倒数第二个节点
    public static void main3(String[] args) {
        MyList one=new MyList();
        for(int i=10;i<16;i++)
        {
            one.insertTail(i+3);
        }
        one.show();
        MyList.List ret=one.ReciprocalNode(one.head,2);
        System.out.println("\n"+ret.data);
    }
    //取中心节点
    public static void main2(String[] args) {
        MyList one=new MyList();
        for(int i=10;i<16;i++)
        {
            one.insertTail(i+3);
        }
            one.show();
            MyList.List ret=one.centre(one.head);
        System.out.println("\n"+ret.data);
    }

    //反转链表和两个有序链表合并为一个新的有序链表
    public static void main1(String[] args) {
        MyList one=new MyList();
        for(int i=10;i<15;i++)
        {
           /* Random fw=new Random();
            one.insertHead(fw.nextInt(50));*/
            one.insertTail(i+3);
        }
        one.show(); System.out.println();
      /*
          反转链表
        one.reversal();
        one.show();*/
        MyList two=new MyList();
        for(int i=10;i<15;i++)
        {
            /*Random fw=new Random();
            two.insertHead(fw.nextInt(50));*/
            two.insertTail(i+1);
        }
        two.show(); System.out.println();
        MyList.List ret= Connect(one.head,two.head);
        one.show(ret);
    }


}
